import Vue from 'vue'
import App from './Main.vue'
import store from './store'

// import manage from './manage/router.js'
import content from './content/router'
// import wage from './wage/router'
// import setting from './setting/router'
import Cookies from 'js-cookie';
import login from './login/router'
import superLogin from './superLogin/router'
import Router from 'vue-router'
import './registerServiceWorker'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'

import './icons' // icon


// base64
// import { Base64 } from 'js-base64';
import http from './server/fetch.js'
Vue.prototype.http = http

// import layer from 'vue-layer'
// Vue.prototype.$layer = layer({
//     msgtime: 3,//目前只有一项，即msg方法的默认消失时间，单位：秒
// });

Vue.use(Viewer)
Viewer.setDefaults({
	Options: {
		'inline': true,
		'button': true,
		'navbar': true,
		'title': true,
		'toolbar': true,
		'tooltip': true,
		'movable': true,
		'zoomable': true,
		'rotatable': true,
		'scalable': true,
		'transition': true,
		'fullscreen': true,
		'keyboard': true,
		'url': 'data-source'
	}
})
Vue.use(ElementUI)
Vue.use(Router)

const routes = [
	...content,
	// ...wage,
	// ...setting
	/* ...login */
]
login[0].props = {
	go: 'sales',
}
// superLogin[0].props = {
//     go: 'institutionalFramework',
// }
const router = new Router({
	routes: [{
		path: '/',
		name: 'systemManage',
		redirect: '/systemManage',
		component: () => import('./App.vue'),
		children: routes
	}, ...login, ...superLogin]
})

/**
 * 路由拦截器
 */
router.beforeEach((to, from, next) => {
	//if (!Cookies.get('Token') && to.name !== 'login' && to.name !== 'superLogin' && to.name !== 'register') { // 判断是否已经登录且前往的页面不是登录页
	if (!Cookies.get('Token') && to.name !== 'login') { 	
		next({
			name: 'login'
		});
	} else if (Cookies.get('Token') && to.name === 'login') { // 判断是否已经登录且前往的是登录页
		next({
			name: 'systemManage'
		});
	} else {
		next();
	}
})
router.afterEach((to) => {
	store.commit('UpActive', to)
})

new Vue({
	router,
	store,
	created() {
		this.$store.commit('TopMenuData', routes)
	},
	render: h => h(App)
}).$mount('#app')
